package disjunction.extensions.view
{
	import disjunction.core.*;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.geom.*;
	
	public class BlitterView extends IView
	{
		private var _spriteSheets:Object = {};
		
		private var _blitmap:Bitmap;
		private var _buffer:BitmapData;
		private var _scale:Number;
		
		private var _testBmd:BitmapData; //DEV
		//[Embed("assets/monolith.png")] private var MonolithGraphic:Class;
			
		protected override function createEntity(entity:Object):Object
		{
			return null;
		}
		
		protected override function destroyEntity(entity:Object):void
		{
		}
		
		protected override function updateEntityView(entityView:Object, entityModel:Object):void
		{
			//Returns a multi-part transform containing actual pos, rot, and scale of entity.
			//var transform:TransformInfo = camera.transform(
			//	(entityModel as IEntityPositionModel).x,
			//	(entityModel as IEntityPositionModel).y,
			//	(entityModel as IEntityScaleModel).scaleX,
			//	(entityModel as IEntityScaleModel).scaleY,
			//	(entityModel as IEntityRotationModel).rotationZ
			//);
			
			//for each entity, pass camera a set of: position, rotation, scale
			//position's Z component specifies which parallax layer it is in (there are an
			//infinite number)
			//entities with z == 0 won't be rendered (too close to camera)
			//however within a layer, there is further depth ordering, eg. player and floor
			//show no perceivable difference in distance, i.e. on same layer, so they must be 
			//depth-ordered to ensure player appears on top. alternaively, since depth is a
			//Number and not an int, we can simply up the depth very slightly in order to
			//ensure this -- without added complexity in the framework.
			
			//then of course, when we actually render, all entities must be drawn in order of
			//decreasing Z. For DisplayObject view, this is handled differently since Z is
			//natively supported for FP10 -- thus no explicit ordering is (presumably) needed.
			
			//camera.transform(entityView, entityModel);
			
			
			if (entityModel is IEntityPositionModel)
			{
				(entityView as BitmapSprite).x = (entityModel as IEntityPositionModel).x;
				(entityView as BitmapSprite).y = (entityModel as IEntityPositionModel).y;
			}
			
			if (entityModel is IEntityScaleModel)
			{
				(entityView as BitmapSprite).scaleX = (entityModel as IEntityScaleModel).scaleX;
				(entityView as BitmapSprite).scaleY = (entityModel as IEntityScaleModel).scaleY;
			}
			
			if (entityModel is IEntityRotationModel)
			{
				(entityView as BitmapSprite).rotation = (entityModel as IEntityRotationModel).rotationZ;
			}
			
			(entityView as BitmapSprite).draw(_buffer);
		}
		
	}
}